<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>轮播图</title>
    <style>
        .carousel-container {
            width: 500px;
            height: 300px;
            margin: 0 auto;
            overflow: hidden;
            position: relative;
        }

        .carousel-images {
            display: flex;
            width: 600%; /* 图片数量 * 100% */
            transition: transform 0.5s ease-in-out;
        }
        .test-images {
            display: flex;
            width: 25%; /* 图片数量 * 100% */
            transition: transform 0.5s ease-in-out;
        }
        .test-images img {
            width: 100%;
            height: 100%;
            transform: translateX(50px);
        }
        .carousel-images img {
            width: 16.666%; /* 100% / 图片数量 */
            height: 100%;
            object-fit: cover;
        }

        .carousel-button {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background-color: rgba(0, 0, 0, 0.5);
            color: white;
            border: none;
            padding: 10px;
            cursor: pointer;
        }

        .prev-button {
            left: 10px;
        }

        .next-button {
            right: 10px;
        }
    </style>
</head>
<body>
    <h1>显示轮播图</h1>
    <div class="carousel-container">
        <div class="carousel-images">
            <img src="./img/1.png" alt="图片 1">
            <img src="./img/2.png" alt="图片 2">
            <img src="./img/3.png" alt="图片 3">
            <img src="./img/4.png" alt="图片 4">
            <img src="./img/5.png" alt="图片 5">
            <img src="./img/6.png" alt="图片 6">
        </div>
        <button class="carousel-button prev-button" onclick="prevSlide()">←</button>
        <button class="carousel-button next-button" onclick="nextSlide()">→</button>
    </div>
    <div class="new-container">
        <div class="test-images">
            <img src="./img/1.png" alt="">
        </div>
    </div>
    <script>
        const carouselImages = document.querySelector('.carousel-images');
        const images = document.querySelectorAll('.carousel-images img');
        let currentIndex = 0;
        const slideWidth = images[0].clientWidth;

        // 自动轮播
        let autoplayInterval = setInterval(nextSlide, 3000);

        function nextSlide() {
            clearInterval(autoplayInterval);
            currentIndex = (currentIndex + 1) % images.length;
            updateCarousel();
            autoplayInterval = setInterval(nextSlide, 3000);
        }

        function prevSlide() {
            clearInterval(autoplayInterval);
            currentIndex = (currentIndex - 1 + images.length) % images.length;
            updateCarousel();
            autoplayInterval = setInterval(nextSlide, 3000);
        }

        function updateCarousel() {
            carouselImages.style.transform = `translateX(-${currentIndex * slideWidth}px)`;
        }
    </script>
</body>
</html>